package com.lotus.lqmp.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lotus.lqmp.base.biz.bean.PageQuery;
import com.lotus.lqmp.service.biz.DeliverablesTemplateConfigBizService;
import com.lotus.lqmp.service.controller.vo.req.DeliverablesAddReq;
import com.lotus.lqmp.service.controller.vo.req.DeliverablesDeleteReq;
import com.lotus.lqmp.service.controller.vo.req.DeliverablesQueryReq;
import com.lotus.lqmp.service.controller.vo.req.DeliverablesUpdateReq;
import com.lotus.lqmp.service.controller.vo.resp.DeliverablesQueryResp;
import com.lotus.platform.common.model.base.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 交付物模板配置表Controller
 * @author Shiheng.Liu1
 * @date 2022-03-29
 */
@RestController
@RequestMapping("/api/deliverables-template-config")
@Api(tags = "交付物模板")
public class DeliverablesTemplateConfigController {

    @Autowired
    private DeliverablesTemplateConfigBizService deliverablesTemplateConfigBizService;

    /**
     * 分页查询
     * @param queryInfo 分页查询条件
     * @return 分页结果
     */
    @PostMapping("/page")
    @ApiOperation("交付物模板分页查询")
    public BaseResult<Page<DeliverablesQueryResp>> queryForPage(
        @RequestBody PageQuery<DeliverablesQueryReq> queryInfo) {
        return BaseResult.ok(deliverablesTemplateConfigBizService.queryForPage(queryInfo));
    }

    /**
     * 详情查询
     * @param id 记录id
     * @return 记录详情
     */
    @ApiOperation("交付物模板详情查询")
    @PostMapping("/{id}")
    public BaseResult<DeliverablesQueryResp> getById(@PathVariable("id") long id) {
        return BaseResult.ok(deliverablesTemplateConfigBizService.getById(id));
    }

    /**
     * 更新
     * @param deliverablesUpdateReq 变更信息以及变更原因信息
     */
    @PostMapping("/update")
    @ApiOperation("交付物模板更新")
    public BaseResult<Void> update(@RequestBody @Valid DeliverablesUpdateReq deliverablesUpdateReq) {
        deliverablesTemplateConfigBizService.update(deliverablesUpdateReq);
        return BaseResult.ok();
    }

    /**
     * 交付物模板批量删除
     * @param deliverablesDeleteReq 待删除id集合以及原因
     */
    @PostMapping("/delete")
    @ApiOperation("交付物模板批量删除")
    public BaseResult<Void> batchDeleteByIds(@RequestBody @Valid DeliverablesDeleteReq deliverablesDeleteReq) {
        deliverablesTemplateConfigBizService.batchDeleteByIds(deliverablesDeleteReq);
        return BaseResult.ok();
    }

    /**
     * 新增
     * @param deliverablesAddReq 变更信息以及变更原因信息
     */
    @PostMapping("/add")
    @ApiOperation("交付物模板新增")
    public BaseResult<Void> add(@RequestBody @Valid DeliverablesAddReq deliverablesAddReq) {
        deliverablesTemplateConfigBizService.add(deliverablesAddReq);
        return BaseResult.ok();
    }

}
